<template>
	<view class="c-add-li">
							<text class="c-title">上传附件</text>
							
							<uni-file-picker 
							    v-model="infos.pathList" 
								file-mediatype="all"
								@select="select" 
								@progress="progress" 
								@success="success" 
								@fail="fail" 
								:auto-upload='false'
							>
							    <button>选择文件</button>
							</uni-file-picker>
						</view>

</template>

<script>
	export default{
		data(){
			return{
				infos:{
					pathList:[]
				}
			}
		},
		methods:{
			// 上传
						select(e){
							let that = this
							uni.showLoading({
								title: "图片上传中"
							});
							
							const tempFilePaths = e.tempFilePaths;
							for (var i in tempFilePaths) {//多文件
								uni.uploadFile({
									url: 'http://localhost:9000/appointment/test/upLoadFile', //上传接口
									// header: {
									// 	'X-Auth-Token': app.globalData.token
									// },
								filePath: tempFilePaths[i],
								name: 'surface',
								success: (uploadFileRes) => {
									uni.hideLoading();
									const back = JSON.stringify(uploadFileRes.data);
									alert(back)
									// if (uploadFileRes.statusCode == 200) {	
									// 	that.infos.pathList.push(back.data);
									// } else {
									// 	uni.showToast(back.msg)
									// }
								},
								fail: () => {
									uni.hideLoading();
									uni.showToast("图片上传失败，请联系开发！")
								},
								complete: function() {
									uni.hideLoading();
								}
							});
						}
						   
						},
						// 获取上传进度
						progress(e){
						    console.log('上传进度：',e)
						},
						
						// 上传成功
						success(e){
						    console.log('上传成功')
						},
						
						// 上传失败
						fail(e){
						    console.log('上传失败：',e)
						},

		}
	}
</script>

<style>
</style>
